package com.seari.controller;

import com.seari.annotation.AppCacheName;
import com.seari.pojo.MessageBean;
import com.seari.service.PassengerFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @ClassName PassengerFlowController
 * @Description 客流量
 * @Author LANDSUS
 * @Date 2021/4/27 14:50
 * @Version 1.0
 */
@RestController
@RequestMapping("flow")
public class PassengerFlowController {

    @Autowired
    private PassengerFlowService service;

    /**
     * @apiGroup 客流量
     * @api {All} /flow/stationFlow 车站进出入站客流量
     * @apiDescription 车站实时出入站客流量
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      STATION_ID: '站ID',
     *      ENTER: '入站客流量',
     *      EXIT: '出站客流量',
     * }
     * @apiVersion 0.0.1
     */
    @RequestMapping("/stationFlow")
    @AppCacheName("stationFlow")
    public MessageBean stationFlow(HttpServletRequest request){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.stationFlow();
        result.setData(data);
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/stationTodayTotal/{type} 车站今日总进出站客流量
     * @apiDescription 车站今日总进出站客流量
     * @apiParam {String} type 排序方式（in：入站从高到低、out：出站从高到低）
     * @apiParamExample 请求示例
     * /flow/stationTodayTotal/in
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      STATION_NAME_CN: '站名',
     *      DAYINPASSENGERFLOW: '入站客流量',
     *      DAYOUTPASSENGERFLOW: '出站客流量'
     * }
     * @apiVersion 0.0.1
     */
    @RequestMapping("/stationTodayTotal/{type}")
    @AppCacheName("stationTodayTotal")
    public MessageBean stationFlowTodayTotal(HttpServletRequest request,@PathVariable String type){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.stationFlowTodayTotal(type);
        result.setData(data);
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/totalDate 今日总数据
     * @apiDescription 今日所有车站的总客流量+在线列车总数+实时进出站客流+实时限流车站数
     * @apiParamExample 请求示例
     * /totalDate
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *    "dayPassengerflow5Min": 19903,  5分钟总客流
     *    "dayNetPassengerflow": 156301,  在网客流
     *    "dayPassengerflow": 9978965,  查询当天总客流
     *    "todayTrainNum": "517",  在线列车总数
     *    "trulyEnter": 19742,  实时进站客流
     *    "trulyExit": 24054,  实时出站客流
     *    "limitStationNum": 0 实时限流车站数
     *}
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/totalDate", produces = "application/json")
    @AppCacheName("totalDate")
    public MessageBean totalDate(HttpServletRequest request){
        MessageBean result = new MessageBean();
        Map data = service.totalDate();
        result.setData(data);
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/total4Station/{type} 虹桥商务区/五大新城今日累计客流、行政区今日累计客流、今日车站客流
     * @apiDescription 今日总客流量
     * @apiParam {String} type 查询类型。s 以站为单位，显示前十；d 以区为单位，显示全部;n 以五大新城+虹桥商业区为单位
     * @apiParamExample 请求示例
     * /total4Station/s
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * type = s
     * {
     *      "TOTAL": 178241,   今日总客运量
     *      "STATION_NAME_CN": "江苏路",  站名
     *      "STREAM_URL": "http://172.20.31.151:8000/live/104.m3u8",  视频url
     *      "MORNING_PEAK_URL": "http://172.20.31.151:8000/live/1234.mp4", 早高峰视频url 无视频时返回null
     *      "INDEX": 10,    站排名
     *      "STATION_ID": [   当前站名称含有的站id
     *          "0242",
     *          "1147"
     *      ],
     *}
     * type = d
     *{
     *      "TOTAL": 3435918, 今日总客运量
     *      "STATION_NUM": 133, 区内站点数
     *      "LINE_NUM": 12, 区内线路数
     *      "ENTER": 10354, 进站客流量
     *      "DISTRICT_NAME_CN": "浦东", 区名
     *      "EXIT": 16251 出站客流量,
     *      "TOTAL_ENTER": 941560,  今日总进站客流
     *      "TOTAL_EXIT": 833739,  今日总出站客流
     *}
     * type = n
     *{
     *      "TOTAL": 318707, 今日总客运量
     *      "NEW_DISTRICT_NAME_CN": "虹桥商务区" 新城名
     *}
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/total4Station/{type}", produces = "application/json")
    @AppCacheName("totalInfo4DifferentSide")
    public MessageBean total4Station(HttpServletRequest request,@PathVariable String type){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.total4Station(type);
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/true4District 行政区实时在网客流
     * @apiDescription 实时在网客流
     * @apiParamExample 请求示例
     * /true4District
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      '区名': '实时在网客流',
     * }
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/true4District", produces = "application/json")
    @AppCacheName("trulyOnLine4District")
    public MessageBean true4District(HttpServletRequest request){
        MessageBean result = new MessageBean();
        Map data = service.true4District();
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/districtFlow 行政区五分钟进出站客流
     * @apiDescription 以行政区为单位
     * @apiParamExample 请求示例
     * /districtFlow
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      'ENTER': '入站客流',
     *      'EXIT':'出站客流',
     *      'DISTRICT_NAME_CN':'区名'
     * }
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/districtFlow", produces = "application/json")
    @AppCacheName("districtFlow")
    public MessageBean districtFlow(HttpServletRequest request){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.districtFlow();
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/true4NewDistrict 五大新城+虹桥实时在网客流
     * @apiDescription 五大新城+虹桥商务区实时在网客流
     * @apiParamExample 请求示例
     * /true4NewDistrict
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      '区名': '实时在网客流',
     * }
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/true4NewDistrict", produces = "application/json")
    @AppCacheName("trulyOnLine4NewDistrict")
    public MessageBean true4NewDistrict(HttpServletRequest request){
        MessageBean result = new MessageBean();
        Map data = service.true4NewDistrict();
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/newDistrictFlow 嘉定新城实时进出站客流
     * @apiDescription 五大新城+虹桥实时进出站客流量
     * @apiParamExample 请求示例
     * /newDistrictFlow
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * "松江新城": {
     *      "flow": [
     *             {
     *                 "EXIT_TIMES": 2000,
     *                 "STATION_NAME_CN": "松江南站",
     *                 "ENTER_TIMES": 6200
     *             },
     *             {
     *                 "EXIT_TIMES": 1600,
     *                 "STATION_NAME_CN": "醉白池",
     *                 "ENTER_TIMES": 3800
     *             },
     *             {
     *                 "EXIT_TIMES": 6000,
     *                 "STATION_NAME_CN": "松江体育中心",
     *                 "ENTER_TIMES": 8200
     *             },
     *             {
     *                 "EXIT_TIMES": 10700,
     *                 "STATION_NAME_CN": "松江大学城",
     *                 "ENTER_TIMES": 12400
     *             },
     *             {
     *                 "EXIT_TIMES": 4100,
     *                 "STATION_NAME_CN": "松江新城",
     *                 "ENTER_TIMES": 4800
     *             }
     *      ]
     * },
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/newDistrictFlow", produces = "application/json")
    @AppCacheName("newDistrictFlow")
    public MessageBean newDistrictFlow(HttpServletRequest request){
        MessageBean result = new MessageBean();
        Map<String, Object> data = service.newDistrictFlow();
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/newDistrictDailyInAndOutFlow 五大新城+虹桥面板
     * @apiDescription 五大新城+虹桥今日累计进出站客流量、降雨量判断天气、气温、风力等级、风向
     * @apiParamExample 请求示例
     * /newDistrictDailyInAndOutFlow
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      "LINE_ID": [ 区内线路名称
     *          "17"
     *      ],
     *      'ENTER': '输入客流',
     *      'EXIT':'输出客流',
     *      'NEW_DISTRICT_NAME_CN':'区名',
     *      "WEATHER": {
     *          "PRE": "晴", 天气
     *          "TEWIN": "南风", 风向
     *          "TEM": 29, 温度
     *          "WIN": "1级" 风力
     *      },
     *      "STATION_NUM": 4, 区内站点个数
     * }
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/newDistrictDailyInAndOutFlow", produces = "application/json")
    @AppCacheName("newDistrictDisplayBoard")
    public MessageBean newDistrictDailyInAndOutFlow(HttpServletRequest request){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.newDistrictDailyInAndOutFlow(service.queryNewDistrictWeather());
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/jinBo 进博会相关
     * @apiDescription 进博会相关
     * @apiParamExample 请求示例
     * /flow/jinBo
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     *{
     *      LINE_ID": [  包含的线路id
     *          17
     *      ],
     *      "TOTAL_FLOW": 13028,  总客流量
     *      "STATION_NAME_CN": "诸光路",  站点名称
     *      "ENTER": 23,  进站客流
     *      "STATION_ID": "1722",  站点id
     *      "EXIT": 119  出站客流
     *}
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/jinBo", produces = "application/json")
    @AppCacheName("aboutJB")
    public MessageBean jinBo(HttpServletRequest request){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.jinBo();
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }

    /**
     * @apiGroup 客流量
     * @api {ALL} /flow/monitor 6个车站的实时和早高峰监控
     * @apiDescription 6个车站的实时和早高峰监控
     * @apiParamExample 请求示例
     * /flow/monitor6station
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     *{
     *    "MORNING_PEAK_URL": "http://172.20.127.60:2080/2021/page2/resources/jiangsulu.mp4",
     *    "STATION_NAME_CN": "江苏路",
     *    "STREAM_URL": "http://172.20.31.151:8000/live/104.m3u8",
     *    "STATION_ID": "1147"
     *},
     * @apiVersion 0.0.1
     */
    @RequestMapping(value = "/monitor6station", produces = "application/json")
    @AppCacheName("monitor6station")
    public MessageBean monitor(HttpServletRequest request){
        MessageBean result = new MessageBean();
        List<Map<String, Object>> data = service.monitor6station();
        result.setData(data);
        result.setTotal(data.size());
        result.setCode("200");
        return result;
    }
}
